﻿<template>
  <div :class="className">
    <!-- style -->
    <div v-html="css"></div>
    <div class="html-box">
      <div v-if="datas.list <= 0" style="font-weight: bold; font-size: 18px; line-height: 50px; text-align: center;">
        请添加订单列表
      </div>

      <div id="new_orderlist">
        <!--只有一个订单的样式 -->
        <template v-if="datas.list.length == 1 && datas.show_tab">
          <div>
            <div class="ordertltie" @click.stop="toUrl({ id: 0, uikey: datas.list[0].uikey, name: datas.list[0].name, component: datas.list[0].component, text: '' })">
              <div class="spare"></div>
              <div class="ordername">{{ datas.list[0].name || datas.list[0].component }}</div>
              <div class="">
                <i class="iconfont icon-member_right"></i>
              </div>
            </div>
          </div>
        </template>

        <ul class="tab_list" v-if="datas.list.length > 1 && datas.show_tab">
          <!--多个订单的样式切换-->
          <van-tabs
            v-model="active"
            swipeable
            :ellipsis="false"
            :background="datas.tab_bg_color"
            :title-active-color="datas.tab_active_color"
            :color="datas.tab_active_color"
            :title-inactive-color="datas.tab_color"
            id="tab"
          >
            <van-tab :title="item.name || item.component" v-for="(item, i) in datas.list" :name="i" :key="i" class="tabChild"></van-tab>
          </van-tabs>
        </ul>

        <template v-for="(order, index) in datas.list">
          <div class="order_all" v-show="active == index" :key="index">
            <div
              class="order_pub"
              v-for="(item, i) in order.remote_data.list"
              :key="i"
              @click.stop="toUrl({ id: item.id, uikey: order.uikey, name: order.name, component: order.component, text: item.text, status: item.status })"
            >
              <div>
                <div class="badge" v-if="item.total != 0">{{ item.total }}</div>
                <img class="order_img" :src="item.image || emptyImage" alt="" />
                <span>{{ item.text }}</span>
              </div>
            </div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import emptyImage from "@/assets/images/new_diy/image.png";
// 自定义样式
const css = function() {
  if (this.datas.preview_color) {
    const { preview_color, text_color, tab_bg_color, tab_color, tab_active_color,margin_LR,padding_TB,border_radius } = this.datas;

    return `
      .component-${this.id} .html-box {
          background-color: ${preview_color.color};
          background-image: url(${preview_color.isColor == 2 ? preview_color.image : ""});
          background-size: 100% 100%;
          background-position: center;
          background-repeat: no-repeat;
          padding: ${padding_TB}px 0;
      }

      .component-${this.id} .html-box #new_orderlist{
        margin: 0 ${margin_LR}px;
        border-radius: ${border_radius}px;
        overflow: hidden;
      }

      .component-${this.id} .order_all .order_pub{
          color: ${text_color};
      }

      .component-${this.id} .ordertltie {
          background-color: ${tab_bg_color};
      }

      .component-${this.id} .spare {
          background-color: ${tab_active_color};
      }

      .component-${this.id} .ordername {
          color: ${tab_color};
      }

      .component-${this.id}  .nav-bgimage{
          background-color: ${tab_bg_color};
          color: ${tab_color};
      }

      .component-${this.id}  .nav-bgimage .nav-selected{
          color: ${tab_active_color};
          border-bottom: 2px solid ${tab_active_color};
      }
  `;
  }
};

export default {
  props: ["id", "datas", "member_order", "Order"],
  data() {
    return {
      emptyImage,
      active: ""
    };
  },
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    }
  },
  methods: {
    toUrl(data) {
      // 后续新开发的，尽量orderType 为接口返回的 component_key !!!!（和前端装修后台开发人员约定好命名）

      // 暂存，暂时用来兼容处理之前的老开发，后续优化干掉 ========================
      let STATUS = data.id;
      if(data.status !== undefined && data.status !== null) STATUS = data.status;
      let _routerName = "";
      if (data.uikey == "U_memberorderlive_install") {
        return this.$router.push(this.fun.getUrl("installationSeverMemberHome", {}, { status: STATUS.toString() }));
      }
      if (data.uikey == "U_memberorderlive_install_worker") {
        return this.$router.push(this.fun.getUrl("installationSeverHome", {}, { status: STATUS == -1 ? 1 : STATUS + 2 }));
      }
      if (data.uikey == "U_memberordercps") {
        _routerName = STATUS == 3 ? "cpsCouponList" : "cpsOrderList";
        return this.$router.push(this.fun.getUrl(_routerName, {}, { status: STATUS, title: data.name || data.component }));
      }
      if (data.uikey == "U_coupon_store_order") {
        return this.$router.push(this.fun.getUrl("ticketOrderList", {}, { status: STATUS, title: data.name || data.component }));
      }
      if (data.uikey == "U_tiktok_cps_order") {
        return this.$router.push(this.fun.getUrl("TikTokOrder", {}, { status: STATUS }));
      }
      if (data.uikey == "U_meituan_group_buy_order") {
        return this.$router.push(this.fun.getUrl("meituan_refund_order", {}, { status: STATUS }));
      }
      if (data.uikey == "U_meituan_order") {
        return this.$router.push(this.fun.getUrl("MeiTuanOrder", {}, { status: STATUS }));
      }
      if (data.uikey == "U_unionCps_order") {
        return this.$router.push(this.fun.getUrl("unionCpsOrder", { status: STATUS }, {}));
      }

      let _oldPluDataCMPT = {
        // 兼容老数据跳转参数问题。
        U_memberorder: "shop",
        U_memberorderhotel: "hotel",
        U_memberorderrelease: "lease_toy",
        U_memberordergroup: "groups",
        U_memberordergroup_ywm: "ywmgroups",
        U_memberordergrab: "grabGroup",
        U_memberordernew_group: "groupWork",
        U_yz_supply_cake: "sachertorte"
      };
      // 暂存，处理老开发 end =====================================

      if (data.text.indexOf("售后") > -1) {
        // 有售后字样，跳转售后页面
        return this.$router.push(this.fun.getUrl("aftersaleslist", { orderType: _oldPluDataCMPT[data.uikey] || data.uikey }));
      }
      this.$router.push(this.fun.getUrl("orderlist", { status: STATUS.toString(), orderType: _oldPluDataCMPT[data.uikey] || data.uikey }, { title: data.name || data.component }));
    }
  }
};
</script>

<style lang="scss" scoped>
// 默认
.component-wrapper {
  width: 100%;
}

.html-box {
  min-height: 30px;
}

.badge {
  position: absolute;
  left: 56%;
  top: 0.125rem;
  background-color: #fff;
  border-radius: 0.625rem;
  color: #f15353;
  line-height: 0.875rem;
  font-size: 12px;
  padding: 0 0.2rem;
  border: solid 1px #f15353;
}

.ordertltie {
  text-align: left;
  width: 100%;
  height: 40px;
  // border-bottom: 1px solid #ebebeb;
  box-sizing: border-box;
  position: relative;
  display: flex;
  padding: 0 14px;
  align-items: center;

  .spare {
    width: 4px;
    height: 16px;
    border-radius: 1px;

    /* background-color: #f15353; */
    // margin-top: 12px;
    margin-right: 6px;
  }

  i {
    line-height: 40px;
    color: #c9c9c9;
    font-size: 20px;
    float: right;
    position: absolute;
    right: 14px;
    top: 0;
  }

  .ordername {
    float: left;
    line-height: 40px;
    font-size: 16px;

    /* color: #333; */
    font-weight: bold;
  }
}

.order_all {
  padding: 10px 0;
  color: #333;
  display: flex;
  justify-content: space-around;
}

.order_img {
  width: 36px;
  height: 36px;
  display: block;
  margin: 0 auto;
}

.order_pub {
  display: flex;
  flex-direction: column;
  padding-top: 2px;
  text-align: center;
  position: relative;
  font-size: 12px;
  width: 25%;
  word-break: break-all;

  i {
    font-size: 24px;
    color: #999;
    margin: 0 auto;
  }
}
</style>
